package XishiBackend.services.microsite;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import XishiBackend.models.entity.Dishes;
import XishiBackend.models.entity.DishesType;
import XishiBackend.models.repository.DishesRepository;
import XishiBackend.models.repository.DishesTypeRepository;
import XishiBackend.models.repository.RestaurantRepository;

@Service
@Transactional
public class MicrositeDishesService {
    @Autowired
    private DishesRepository dR;
    @Autowired
    private DishesTypeRepository dtR;
    @Autowired
    private RestaurantRepository rR;
    
    public Dishes findOne(long dishesId) {
        return dR.findOne(dishesId);
    }
    
    public List<Dishes> findAll() {
        Iterator<Dishes> iter = dR.findAll().iterator();
        List<Dishes> list = new ArrayList<Dishes>();
        while(iter.hasNext()) {
            Dishes d = iter.next();
            if(d.isOnShow()) {
                list.add(d);
            }
        }
        return list;
    }
    
    public Map<String,String> findDishesType() {
        Iterator<DishesType> iter = dtR.findAll().iterator();
        Map<String,String> map = new HashMap<String,String>();
        while(iter.hasNext()) {
            DishesType dt = iter.next();
            map.put(""+dt.getId(), dt.getName());
        }
        return map;
    }
}
